#include "StdAfx.h"
#include "Reader.h"
#define GetCurrentDir getcwd

using namespace std;
Reader::Reader(void)
{

}


Reader::~Reader(void)
{

}

char * Reader::GetCurrentDirectory()
{
	char * cCurrentPath = (char *)malloc(_MAX_PATH);
	GetCurrentDir(cCurrentPath, _MAX_PATH);
	return cCurrentPath;
}

string Reader::readFileToString(char *fileName)
{
	string buffer = "ERROR";
	char * fullPath = mergeTwoStrings(GetCurrentDirectory(),fileName);
		if(FileExists(fullPath)){
		cout << "fullPath: " << fullPath << endl;
		std::ifstream fin(fullPath);
		getline(fin, buffer, char(-1));
		fin.close();
	}

	delete fullPath; //omdat we in mergeTwoStrings new gebruiken!
	return buffer;
}

char* Reader::mergeTwoStrings(char* str1, char* str2)
{
	char* separator = "\\";
	char* retVal = new char[strlen(str1) + strlen(str2) + strlen(separator) + 1];
	
	// Assemble the string
	strcpy(retVal,str1);
	strcpy(&retVal[strlen(str1)],separator);
	strcpy(&retVal[strlen(str1) + strlen(separator)],str2);

	return retVal;
}

bool Reader::FileExists(const char* fileName)
{
	ifstream ifile(fileName);
	return ifile;
}
